home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / month.prg < prev    next >
Text File  |  1991-08-15  |  4KB  |  114 lines

  1. /*
  2.  * File......: MONTH.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   15 Aug 1991 23:05:42  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/month.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/month.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:05:42   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:52:28   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:01:46   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_MONTH()
  31.  *  $CATEGORY$
  32.  *     Date/Time
  33.  *  $ONELINER$
  34.  *     Return Calendar or Fiscal Month Data
  35.  *  $SYNTAX$
  36.  *     FT_MONTH( [ <dGivenDate> ], [nMonthNum] ) -> aDateInfo
  37.  *  $ARGUMENTS$
  38.  *     <dGivenDate> is any valid date in any date format.  Defaults
  39.  *     to current system date if not supplied.
  40.  *
  41.  *     <nMonthNum> is a number from 1 to 12 signifying a month.
  42.  *     Defaults to current month if not supplied.
  43.  *  $RETURNS$
  44.  *     A three element array containing the following data:
  45.  *
  46.  *        aDateInfo[1] - The year and month as a character string "YYYYMM"
  47.  *        aDateInfo[2] - The beginning date of the month
  48.  *        aDateInfo[3] - The ending date of the month
  49.  *  $DESCRIPTION$
  50.  *     FT_MONTH() returns an array containing data about the month
  51.  *     containing the given date.
  52.  *
  53.  *     Normally the return data will be based on a year beginning
  54.  *     on January 1st with weeks beginning on Sunday.
  55.  *
  56.  *     The beginning of year date and/or beginning of week day can be
  57.  *     changed by using FT_DATECNFG(), which will affect all subsequent
  58.  *     calls to FT_MONTH() until another call to FT_DATECNFG().
  59.  *
  60.  *     The beginning of year date and beginning of week day may be reset
  61.  *     to January 1 and Sunday by calling FT_DATECNFG() with no
  62.  *     parameters.
  63.  *  $EXAMPLES$
  64.  *     // get info about month containing 9/15/90
  65.  *     aDateInfo := FT_MONTH( CTOD("09/15/90") )
  66.  *     ? aDateInfo[1]   //  199009       (9th month)
  67.  *     ? aDateInfo[2]   //  09/01/90     beginning of month 9
  68.  *     ? aDateInfo[3]   //  09/30/90     end of week month 9
  69.  *
  70.  *     // get info about month 5 in year containing 9/15/90
  71.  *     aDateInfo := FT_MONTH( CTOD("09/15/90"), 5 )
  72.  *     ? aDateInfo[1]   //  199005
  73.  *     ? aDateInfo[2]   //  05/01/90   beginning of month 5
  74.  *     ? aDateInfo[3]   //  05/31/90   end of month 5
  75.  *
  76.  *     // get info about month 5 in current year
  77.  *     aDateInfo := FT_MONTH( , 5 )
  78.  *     ? aDateInfo[1]   //  199105
  79.  *     ? aDateInfo[2]   //  05/01/91   beginning of month 5
  80.  *     ? aDateInfo[3]   //  05/31/91   end of month 5
  81.  *  $SEEALSO$
  82.  *     FT_DATECNFG() FT_WEEK() FT_QTR() FT_YEAR()
  83.  *  $END$
  84. */
  85.  
  86. FUNCTION FT_MONTH(dGivenDate,nMonthNum)
  87. LOCAL lIsMonth, nTemp, aRetVal, aTemp, cFY_Start
  88. LOCAL cDateFormat := SET(_SET_DATEFORMAT)
  89.  
  90.   aTemp := FT_DATECNFG()
  91.   cFY_Start := aTemp[1]
  92.   SET(_SET_DATEFORMAT, "yyyy.mm.dd")
  93.   IF dGivenDate == NIL .OR. !VALTYPE(dGivenDate) $ 'ND'
  94.      dGivenDate := DATE()
  95.   ELSEIF VALTYPE(dGivenDate) == 'N'
  96.      nMonthNum := dGivenDate
  97.      dGivenDate := DATE()
  98.   ENDIF
  99.   lIsMonth := IF(nMonthNum == NIL .OR. VALTYPE(nMonthNum) != 'N', .F., .T.)
  100.   nMonthNum := IF(lIsMonth, IF(nMonthNum > 0 .AND. nMonthNum < 13, ;
  101.                              nMonthNum, 12), NIL)
  102.  
  103.   aRetVal := FT_YEAR(dGivenDate)
  104.   dGivenDate := IF(lIsMonth, FT_MADD(aRetVal[2], nMonthNum - 1), dGivenDate)
  105.   nTemp := MONTH(dGivenDate) - MONTH(aRetVal[2])
  106.   nTemp += IF(nTemp >= 0, 1, 13)
  107.   aRetVal[1] += PADL(LTRIM(STR(nTemp, 2)), 2, '0')
  108.   aRetVal[2] := CTOD( STR(YEAR(dGivenDate), 4) + "." + ;
  109.                  STR(MONTH(dGivenDate), 2) + SUBSTR(cFY_Start,8,3) )
  110.   aRetVal[3] := FT_MADD(aRetVal[2],1) - 1
  111.   SET(_SET_DATEFORMAT, cDateFormat)
  112. RETURN aRetVal
  113.  
  114.